<?php
// app/controller/Index.php

namespace app\controller;

use app\model\User as UserModel;
use core\Controller;
use core\Request;
use core\Response;

class Index extends Controller {
    public function __construct(){
        parent::__construct();
        $this->UserModel = new UserModel();
        $this->response = new Response();
    }
    
    // 用户列表页
    public function index() {
        if($this->request->isPost()){
            $response = $this->response;
            $username = $this->request->param('username', '');
            // var_dump($username);
            // echo "index";
            $where = [
                'deletetime' => null
            ];
            $data =$this->UserModel
            ->with('rank')
            ->where($where)
            ->select();
            // $data =$this->UserModel->where(['id'=>2])->find();
            return $response->json($data);
        }
    }

    // 添加用户
    public function add() {

        var_dump("add");
    }

    // 更新
    public function update(){
        $this->UserModel->startTrans();
        $data = [
            'staffname' => '张四'
        ];
        $status = $this->UserModel->where(['id'=>23])->update($data);

        echo $status;
    }

    // 删除
    public function delete(){
        $status = $this->UserModel->delete(23);
        echo 'status:' . $status;
    }
}